import 'package:coinbaby/common/const/cosnt.dart';
import 'package:coinbaby/common/textstyle/textstyle.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'view/rich_protocol.dart';

class LoginPage extends StatefulWidget {
  @override
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {

  FocusNode _focusNode = FocusNode();
  TextEditingController _controller = TextEditingController();

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
  void _jumpToRoot(){
    SharedPreferences.getInstance().then((value) => value.setBool(AppConst.APP_IS_LOGIN, true));
    Navigator.of(context).pushNamedAndRemoveUntil('/root',(Route<dynamic> route) => false);
  }

  void _jumpSmsCode() {
    Navigator.pushNamed(context, "/smscode");
  }

  void _jumpPwdlogin() {
    Navigator.pushNamed(context, "/pwdlogin");
  }

  @override
  Widget build(BuildContext context) {
    
    final size = MediaQuery.of(context).size;

    return Scaffold(
      resizeToAvoidBottomPadding: false,
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () => _focusNode.unfocus(),
        child: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(25),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: size.height * 0.05,),
                Text("你好，\n欢迎来到币小贝！", 
                  style: AppFont.textStyle(24, const Color(0xff101010), fontWeight: FontWeight.bold),
                ),
                SizedBox(height: size.height * 0.1),
                TextField(
                  inputFormatters: [WhitelistingTextInputFormatter.digitsOnly],
                  keyboardType: TextInputType.number,
                  maxLength: 11,
                  focusNode: _focusNode,
                  controller: _controller,
                  decoration: InputDecoration(
                    hintText: "请输入手机号码",
                    counterText: "", // 删除输入长度限制
                    prefixIcon: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Text("+86"),
                        Icon(Icons.arrow_drop_down)
                      ],
                    ),
                    labelStyle: AppFont.textStyle(14, const Color(0xff101010))
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(top: 10.0),
                  child: Text("未注册的手机号验证后自动创建账户"),
                ),
                InkWell(
                  onTap: _jumpSmsCode,
                  child: Container(
                    width: size.width,
                    height: 50,
                    margin: const EdgeInsets.only(top: 35),
                    decoration: BoxDecoration(
                      color: Colors.red,
                      borderRadius: BorderRadius.circular(10)
                    ),
                    alignment: Alignment.center,
                    child: Text("获取短信验证码", style: AppFont.textStyle(14, Colors.white),),
                  ),
                ),
                InkWell(
                  onTap: _jumpPwdlogin,
                  child: Padding(
                    padding: const EdgeInsets.only(top: 16.0),
                    child: Text("密码登陆"),
                  ),
                ),
                Spacer(),
                RichProtocolView()
              ],
            ),
          ),
        ),
      ),
    );
  }
}